from page import get_page
from 滑块验证码 import slider_img


def login(usernames):
    username = usernames['username']
    password = usernames['password']
    port = usernames['port']
    user_path = usernames['user_path']
    downpath = usernames['down_path']
    page = get_page(port, user_path, downpath)
    page.get('https://fxg.jinritemai.com/login/common')
    page.wait(8)
    shop_list = page.s_eles(".index_roleItem__1-Hwe")
    if not shop_list:
        if page.s_eles('.feige_headerIcon__3CdVk') or page.s_eles('接待'):
            return
        if not page.s_ele('邮箱登录') and not page.s_eles('.FYy4GhPJDlQ9bPKKLUC1'):
            return
        if page.s_eles('.FYy4GhPJDlQ9bPKKLUC1'):
            page.eles('.FYy4GhPJDlQ9bPKKLUC1')[0].click()
            tab = page.get_tab(page.latest_tab)
            tab('邮箱登录').click()
            tab('@name=email').input(username)
            tab('@name=password').click()
            tab.actions.type(password)
            tab('.auxo-checkbox-inner').click(by_js=True)
            tab.wait(2)
            tab('.account-center-submit').click()
            tab.wait(3)
            slider_img(tab)
            return
        page('邮箱登录').click()
        page('@name=email').input(username)
        page('@name=password').click()
        page.actions.type(password)
        page('.auxo-checkbox-inner').click(by_js=True)
        page.wait(2)
        page('.account-center-submit').click()
        page.wait(3)
        slider_img(page)


def login_ing(page, usernames):
    username = usernames['username']
    password = usernames['password']
    port = usernames['port']
    user_path = usernames['user_path']
    down_path = usernames['down_path']
    if not page.s_ele('邮箱登录'):
        return
    page('邮箱登录').click()
    page.wait(1)
    page('@name=email').input(username)
    page('@name=password').click()
    page.actions.type(password)
    page('.auxo-checkbox-inner').click(by_js=True)
    page.wait(2)
    page('.account-center-submit').click()
    page.set.window.mini()
    page.set.tab_to_front()
    page.wait(3)
    slider_img(page)
